package executeEngine.methodInvoke.dynamicInvoke;

import java.lang.invoke.MethodType;

import static java.lang.invoke.MethodHandles.lookup;

class GrandFather {
    public void thinking() {
        System.out.println("grand father");
    }
}

class Father extends GrandFather {
    public void thinking() {
        System.out.println("father");
    }
}

class Son extends Father {
    public void thinking() {
        try {
            lookup().findSpecial(GrandFather.class, "thinking", MethodType.methodType(void.class), getClass())
                    .invoke(this);
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
    }
}

public class Demo1 {
    public static void main(String[] args) {
        GrandFather t = new Son();
        t.thinking();
    }
}
